<script>
	import request from '@/utils/request';
	import cache from '@/utils/cache';
	import colors from '@/mixins/color.js';
	let blue =
		'--view-theme: rgba(29,176,252,1);--view-theme-16:#1db0fc;--view-priceColor:#1db0fc;--view-minorColor:rgba(58, 139, 236, 0.5);--view-minorColorT:rgba(9, 139, 243, 0.1);--view-bntColor:#1db0fc;--view-op-ten: rgba(29,176,252, 0.1);--view-main-start:#1db0fc; --view-main-over:#1db0fc;--view-op-point-four: rgba(29,176,252, 0.04);'
	let green =
		'--view-theme: rgba(66,202,77,1);--view-theme-16: #42ca4d;--view-priceColor:#42ca4d;--view-minorColor:rgba(66,202,77, 0.5);--view-minorColorT:rgba(66,202,77, 0.1);--view-bntColor:#42ca4d;--view-op-ten: rgba(66,202,77, 0.1);--view-main-start:#42ca4d; --view-main-over:#42ca4d;--view-op-point-four: rgba(66,202,77, 0.04);'
	let red =
		'--view-theme: rgba(233,51,35,1);--view-theme-16: #e93323;--view-priceColor:#e93323;--view-minorColor:rgba(233,51,35, 0.5);--view-minorColorT:rgba(233, 51, 35, 0.1);--view-bntColor:#e93323;--view-op-ten: rgba(233,51,35, 0.1);--view-main-start:#e93323; --view-main-over:#e93323;--view-op-point-four: rgba(233,51,35, 0.04);'
	let pink =
		'--view-theme: rgba(255,68,143,1);--view-theme-16:#ff448f;--view-priceColor:#ff448f;--view-minorColor:rgba(255, 68, 143, 0.5);--view-minorColorT:rgba(255, 68, 143, 0.1);--view-bntColor:#ff448f;--view-op-ten: rgba(255,68,143, 0.1);--view-main-start:#ff448f; --view-main-over:#ff448f;--view-op-point-four: rgba(255,68,143, 0.04);'
	let orange =
		'--view-theme: rgba(255, 170, 0, 1); --view-theme-16:#ffaa00;--view-priceColor:#ffaa00;--view-minorColor:rgba(255, 170, 0, 0.5);--view-minorColorT:rgba(255, 170, 0, 0.1);--view-bntColor:#ffaa00;--view-op-ten: rgba(255, 170, 0, 0.1);--view-main-start:#ffaa00; --view-main-over:#ffaa00;--view-op-point-four: rgba(255, 170, 0, 0.04);'
	let gold =
		'--view-theme: rgba(255, 255, 127, 1); --view-theme-16:#ffff66;--view-priceColor:#ffff66;--view-minorColor:rgba(255, 255, 127, 0.5);--view-minorColorT:rgba(255, 255, 127, 0.1);--view-bntColor:#ffff66;--view-op-ten: rgba(255, 255, 127, 0.1);--view-main-start:#ffff66; --view-main-over:#ffff66;--view-op-point-four: rgba(255, 255, 127, 0.04);'
	let purple =
		'--view-theme: rgba(255, 85, 255, 1); --view-theme-16:#ff55ff;--view-priceColor:#ff55ff;--view-minorColor:rgba(255, 85, 255, 0.5);--view-minorColorT:rgba(255, 85, 255, 0.1);--view-bntColor:#ff55ff;--view-op-ten: rgba(255, 85, 255, 0.1);--view-main-start:#ff55ff; --view-main-over:#ff55ff;--view-op-point-four: rgba(255, 85, 255, 0.04);'
	let cyan =
		'--view-theme: rgba(0, 255, 255, 1); --view-theme-16:#66ffff;--view-priceColor:#66ffff;--view-minorColor:rgba(0, 255, 255, 0.5);--view-minorColorT:rgba(0, 255, 255, 0.1);--view-bntColor:#66ffff;--view-op-ten: rgba(0, 255, 255, 0.1);--view-main-start:#66ffff; --view-main-over:#66ffff;--view-op-point-four: rgba(0, 255, 255, 0.04);'

	export default {
		mixins: [colors],
		onLaunch: function() {
			console.log('App Launch');
			this.getPosition();
			this.getTheme();
			this.getCompanyInfo();
		},
		onShow: function() {
			console.log('App Show');
		},
		onHide: function() {
			console.log('App Hide');
		},
		methods: {
			getPosition() {
				console.log('获取定位中');
				let geocode = false;
				// #ifdef MP || APP
				geocode = true;
				// #endif
				return new Promise((resolve, reject) => {
					uni.getLocation({
						type: 'gcj02',
						altitude: true,
						geocode: geocode,
						success: res => {
							cache.set('longitude', res.longitude); //缓存经度
							cache.set('latitude', res.latitude); //缓存纬度
							resolve(res);
						},
						fail: err => {
							console.error("currentLocation fail", err);
							uni.showModal({
								title: '提示',
								showCancel: false,
								content: '获取定位信息失败，请检查设备是否启用定位功能！'
							});
							reject(err);
						}
					})
				})
			},
			getTheme() {
				request.get('index/theme').then(res => {
					console.log('主题', res);
					let themeColor = {
						'name': res.data.name,
						'color': res.data.color,
						'theme': res.data.color_picker,
						'gradient': res.data.gradient_color,
					};
					console.log("主题色", themeColor);
					switch (res.data.color) {
						case 'blue':
							// cache.set('themeColor', '#1db0fc');
							cache.set('viewColor', blue);
							uni.$emit('ok', blue, res.data.status);
							break;
						case 'green':
							// cache.set('themeColor', '#42ca4d');
							cache.set('viewColor', green);
							uni.$emit('ok', green, res.data.status);
							break;
						case 'red':
							// cache.set('themeColor', '#e93323');
							cache.set('viewColor', red);
							uni.$emit('ok', red, res.data.status);
							break;
						case 'pink':
							// cache.set('themeColor', '#ff448f');
							cache.set('viewColor', pink);
							uni.$emit('ok', pink, res.data.status);
							break;
						case 'orange':
							// cache.set('themeColor', '#ffaa00');
							cache.set('viewColor', orange);
							uni.$emit('ok', orange, res.data.status);
							break;
						case 'gold':
							// cache.set('themeColor', '#ffff66');
							cache.set('viewColor', gold);
							uni.$emit('ok', gold, res.data.status);
							break;
						case 'purple':
							// cache.set('themeColor', '#ff55ff');
							cache.set('viewColor', purple);
							uni.$emit('ok', purple, res.data.status);
							break;
						case 'cyan':
							// cache.set('themeColor', '#66ffff');
							cache.set('viewColor', cyan);
							uni.$emit('ok', cyan, res.data.status);
							break;
						default:
							// cache.set('themeColor', '#e93323');
							cache.set('viewColor', red);
							uni.$emit('ok', red, res.data.status);
							break
					}
					cache.set('themeColor', JSON.stringify(themeColor));
				})
			},
			getCompanyInfo() {
				request.get('index/getCopyRight').then(res => {
					// console.log('CompanyInfo', res);
					if (res.code === 1) {
						cache.set('company-info', JSON.stringify(res.data));
						// console.log(JSON.parse(cache.get('company-info')));
					}
				})
			},
		},
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import '/common/css/app.scss';
	@import '/static/fonts/iconfont.css';
</style>